import React from 'react';
import { connect } from 'react-redux'
import styles from './Home/Home.module.less'
import {get} from '@server/request';
import {Switch,Route} from 'react-router-dom'
import {renderRouter} from '@routes/index';
import {message} from 'antd';

 class Home extends React.Component{
  constructor(props){
    super(props);
  }

  toJump(path){
    this.props.history.push(path);
  }
  render(){
    const {routes} = this.props;
    const routesList = renderRouter(routes);
    return(
      <div className={styles.HomeContainer}>
        <img src={require("../assets/images/logo.png")}
          width="180px"
          height="200px"
          alt="LOGO"
          title="LOGO" />
      <p className={styles.AppTitle}>Welecome！React-Template</p>
      <p className={styles.AppRouter}>
          <span onClick={ (e) => this.toJump("/login")}>Jump Login Page</span>
          <span onClick={ (e) => this.toJump("/home/children")}>Jump HomeChildren Page</span>
          <span onClick={ (e) => message.info("Welecome！React-Template")}>Click antd message</span>
        </p> 
      <Switch>
       {routesList}
      </Switch>
      </div>
    )
  }
}

// state
function mapStateToProps(state){
  return state;
}

// dispatch
function mapDispatchToProps(dispath){
  return{
    async add(){
      await get("/dev/api/auth/login?username=admin&password=platform");
      dispath({ type: 'ADD' })
    }
  }
}
export default connect(mapStateToProps,mapDispatchToProps)(Home)